package it.unibo.refolding.pico.mfp;

import it.unimi.dsi.fastutil.bytes.ByteList;

import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class Wave {
  // Should we use generics? Wave<T extends WaveHeader>.
  public final WaveHeader waveHeader;
  public final ByteList waveData;
  public final ByteOrderAndVersion byteOrderAndVersion;
  public final ByteList unsignedNotes;
  private List<ByteList> unsignedLabels;

  public Wave(ByteOrderAndVersion byteOrderAndVersion, WaveHeader waveHeader, ByteList waveData, ByteList unsignedNotes, List<ByteList> unsignedLabels) {
    this.byteOrderAndVersion = byteOrderAndVersion;
    this.waveHeader = Objects.requireNonNull(waveHeader);
    this.waveData = Objects.requireNonNull(waveData);
    this.unsignedNotes = Objects.requireNonNull(unsignedNotes);
    this.unsignedLabels = Objects.requireNonNull(unsignedLabels);
  }

  @Override
  public int hashCode() {
    return Objects.hash(byteOrderAndVersion, waveHeader, waveData, unsignedNotes, unsignedLabels);
  }

  @Override
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("byteOrderAndVersion", byteOrderAndVersion).append(
      "waveHeader", waveHeader).append("len(waveData)", waveData.size()).append("notes", notes()).append("unsignedLabels", labels()).build();
  }

  public String notes() {
    return IgorUtil.unsignedBytesToString(unsignedNotes);
  }
  
  public List<String> labels() {
    return IgorUtil.unsignedBytesListToStringList(unsignedLabels);
  }

  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof Wave)) {
      return false;
    }
    Wave other = (Wave) obj;
    return waveHeader.equals(other.waveHeader) && waveData.equals(other.waveData)
      && unsignedNotes.equals(other.unsignedNotes);
  }
}
